package com.test.login_lejingling_cjl.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.test.login_lejingling_cjl.dto.loginDTO;
import com.test.login_lejingling_cjl.entity.User;
import com.test.login_lejingling_cjl.service.UserService;
import com.test.login_lejingling_cjl.mapper.UserMapper;
import com.test.login_lejingling_cjl.utils.MD5Util;
import org.springframework.beans.BeanUtils;
import org.springframework.stereotype.Service;

/**
* @author 11818
* @description 针对表【user】的数据库操作Service实现
* @createDate 2024-11-12 20:49:50
*/
@Service
public class UserServiceImpl extends ServiceImpl<UserMapper, User>
    implements UserService{

    private final UserMapper userMapper;

    public UserServiceImpl(UserMapper userMapper) {
        this.userMapper = userMapper;
    }

    @Override
    public User login(loginDTO loginDTO) {
        // 对密码进行 MD5 加密
        String encryptedPassword = MD5Util.md5Encrypt(loginDTO.getPassword());

        User user = new User();
        // 执行查询
        user = userMapper.findUser(loginDTO);

        if (user != null) {
            // 构建返回的 DTO 对象
            return user;
        } else {
            return null; // 用户不存在或密码错误
        }
    }
}




